#! /usr/bin/python
import sys
import pefile

if len(sys.argv) < 2:
    print("[*] Usage: [Target DLL file path] [VA]")
    exit()

TargetFilePath=sys.argv[1]
TargetVA = int(sys.argv[2][2:], 16)

#print("... opening file at " + TargetFilePath + " to hunt for nearest export to gadget " + str(hex(GadgetRva)))

pe = pefile.PE(TargetFilePath)

RVA = (TargetVA - pe.OPTIONAL_HEADER.ImageBase)

print(str(hex(RVA)))